package common

import (
	"fmt"
	_ "github.com/go-sql-driver/mysql"
	"github.com/jinzhu/gorm"
)

var (
	db *gorm.DB
	err error
)

func Init(db_name string){
	//给全局变量db赋值，连接mysql驱动

	//changgou-good数据库
	args := fmt.Sprintf("root:root@/%v?charset=utf8&parseTime=True&loc=Local",db_name)
	db, err = gorm.Open("mysql", args)
	db = db.LogMode(true)
	if err != nil {
		panic(err)
	}

}

func GetDB(db_name string) *gorm.DB{
	Init(db_name)
	return db
}
